package com.anlu.base.function;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.anlu.base.function.convert.FormConvert;
import com.anlu.base.function.enums.FunEnum;
import com.anlu.base.function.mode.FormComponentBaseBO;
import com.anlu.base.function.mode.FormComponentValueBaseBO;
import com.anlu.base.function.mode.FormVO;
import com.anlu.base.function.mode.po.FormContentPO;
import com.anlu.base.function.util.FormComponentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
    private final  static  Logger logger = LoggerFactory.getLogger(Main.class);


    static FormComponentBaseBO po2bo(FormContentPO po) {
        FormComponentBaseBO bo = new FormComponentBaseBO<>();
        bo.setKey(po.getComponentKey());
        bo.setType(FunEnum.codeOf(po.getComponentType()));
        bo.setTitle(po.getComponentTitle());
        bo.setValue(bo.getType().getFunction().apply(po.getComponentValue()));
        return bo;
    }

    public static void main(String[] args) {

        FormContentPO formContentPO = new FormContentPO();
        formContentPO.setFormId(1L);
        formContentPO.setComponentType("TEXT");
        formContentPO.setComponentKey("k");
        formContentPO.setComponentTitle("title");

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name","anlu");

        formContentPO.setComponentValue(JSON.toJSONString(jsonObject));
        //从数据库获取po
        FormComponentBaseBO formComponentBaseBO = po2bo(formContentPO);

        FormVO formVO = FormComponentUtil.of(formComponentBaseBO);
        logger.info("formVo={}",formVO.toString());



    }
}
